// src/utils/storage.js
export const useStorage = () => {
  // 获取本地存储
  const getStorage = (key) => {
    try {
      const value = localStorage.getItem(key);
      return value ? JSON.parse(value) : null;
    } catch (error) {
      console.error('Failed to get storage:', error);
      return null;
    }
  };

  // 设置本地存储
  const setStorage = (key, value) => {
    try {
      const serializedValue = JSON.stringify(value);
      localStorage.setItem(key, serializedValue);
    } catch (error) {
      console.error('Failed to set storage:', error);
    }
  };

  // 移除本地存储
  const removeStorage = (key) => {
    try {
      localStorage.removeItem(key);
    } catch (error) {
      console.error('Failed to remove storage:', error);
    }
  };

  return {
    getStorage,
    setStorage,
    removeStorage
  };
};